

package TransportesMarroquin;



import com.mysql.jdbc.Connection;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioSystem;
import javax.swing.JOptionPane;
import net.sf.jxls.exception.ParsePropertyException;
import net.sf.jxls.report.ReportManager;
import net.sf.jxls.report.ReportManagerImpl;
import net.sf.jxls.transformer.XLSTransformer;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

public class Piloto extends javax.swing.JFrame {
    Sueldo s;
    Bono b;
    Descuentos d;
    String file;
    ResultSetTableModel tableModel;
    int codigo;
    int sueldo;
    String nombre = "";
    String apellido = "";
    String nombres= new String();
    String apellidos = new String();
    
    int row;
    String consulta = "SELECT idpiloto,nombre, apellido, licencia, edad, sueldo, bono, descuento, tipopiloto FROM piloto";
    boolean borrar = false ;
    boolean entro = false;
    javax.sound.sampled.Clip sonido;
    
    public Piloto() {
            initComponents();
       
    }


   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        menu = new javax.swing.JPopupMenu(" ");
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        lnum2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jButton5 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        cbus = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cbus1 = new javax.swing.JTextField();
        trash = new javax.swing.JLabel();
        jButton8 = new javax.swing.JButton();

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/sueldo.png"))); // NOI18N
        jMenuItem1.setLabel("Sueldo");
        jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem1MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem1MousePressed(evt);
            }
        });
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        menu.add(jMenuItem1);

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/descuento.png"))); // NOI18N
        jMenuItem2.setText("Descuento");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        menu.add(jMenuItem2);

        jMenuItem3.setText("Pago por Flete");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        menu.add(jMenuItem3);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));

        lnum2.setFont(new java.awt.Font("Tahoma", 1, 18));
        lnum2.setForeground(new java.awt.Color(255, 255, 255));
        lnum2.setText("Pilotos ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lnum2)
                .addContainerGap(596, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lnum2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        try{
            tableModel = new ResultSetTableModel( consulta );
        }catch(Exception e){
            System.out.println("ERROR");
        }
        resultTable.setModel(tableModel);
        resultTable.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        resultTable.setNextFocusableComponent(menu);
        resultTable.setOpaque(false);
        resultTable.setSelectionBackground(new java.awt.Color(255, 255, 255));
        resultTable.setSelectionForeground(new java.awt.Color(0, 0, 0));
        resultTable.setSurrendersFocusOnKeystroke(true);
        resultTable.getTableHeader().setReorderingAllowed(false);
        resultTable.setUpdateSelectionOnSort(false);
        resultTable.setVerifyInputWhenFocusTarget(false);
        resultTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                resultTableMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                resultTableMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                resultTableMouseReleased(evt);
            }
        });
        resultTable.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                resultTableMouseDragged(evt);
            }
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                resultTableMouseMoved(evt);
            }
        });
        jScrollPane1.setViewportView(resultTable);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316277158_filenew.png"))); // NOI18N
        jButton5.setText("Nuevo");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/regresar.png"))); // NOI18N
        jButton3.setText("Regresar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316283555_Dollars.png"))); // NOI18N
        jButton6.setText("Planilla");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316298596_print_16x16.gif"))); // NOI18N
        jButton7.setText("Imprimir");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        cbus.setText("Buscar por Nombre");
        cbus.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbusMouseClicked(evt);
            }
        });
        cbus.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                cbusKeyReleased(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316367384_search.png"))); // NOI18N

        cbus1.setText("Buscar por Apellido");
        cbus1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbus1MouseClicked(evt);
            }
        });
        cbus1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                cbus1KeyReleased(evt);
            }
        });

        trash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/empty.png"))); // NOI18N
        trash.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                trashMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                trashMouseExited(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                trashMouseReleased(evt);
            }
        });
        trash.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                trashMouseMoved(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316393209_mail_new.png"))); // NOI18N
        jButton8.setText("Correo");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(trash, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cbus, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(cbus1, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel1)
                        .addGap(120, 120, 120))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbus1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jButton5)
                        .addGap(11, 11, 11)
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
                        .addComponent(trash, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void resultTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseClicked

       
              int fila = resultTable.rowAtPoint(evt.getPoint());
              
                if (fila > -1)
                {
                      dispose();
                      Object objeto = tableModel.getValueAt(fila, 0);

                     String ja = objeto.toString();
                     int num=Integer.parseInt(ja);
                
                      PilotoSelect va = new PilotoSelect (num);
                      va.setVisible(true);
                      va.setResizable(false);

                     
                }        
        
                  
}//GEN-LAST:event_resultTableMouseClicked

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
dispose();
NuevoPiloto va = new NuevoPiloto();
va.setVisible(true);
     
}//GEN-LAST:event_jButton5ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        dispose();
}//GEN-LAST:event_jButton3ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
       
        
        s = new Sueldo();
        Sueldo.cnom.setText(""+nombre);
        Sueldo.ccod.setText(""+codigo);
        Sueldo.csue.setText(""+sueldo);
        s.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem1MousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1MousePressed

    private void resultTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMousePressed
      // leo la info 
        row = resultTable.rowAtPoint(evt.getPoint());
        
        if(evt.isPopupTrigger()){
         
              
                
          menu.show(resultTable, evt.getX(), evt.getY());
      }
      else{
         borrar=true;
          
      
      }
      
      // accion qee va hacer siempre 
      if (row > -1)
                {
                      
                      Object objeto = tableModel.getValueAt(row, 0);

                     String ja = objeto.toString();
                     // leo el nombre
                     objeto = tableModel.getValueAt(row, 1);
                     nombres = objeto.toString();
                     
                     // leo el apellido 
                     objeto = tableModel.getValueAt(row, 2);
                     apellidos = objeto.toString();
                     
                     codigo=Integer.parseInt(ja);
                     
                     
                     // datos para el sueldo 
                     
                      objeto = tableModel.getValueAt(row, 1);
                     nombre = objeto.toString();
                     
                      objeto = tableModel.getValueAt(row, 5);
                     sueldo = Integer.parseInt(objeto.toString());

                }     
      
     
    }//GEN-LAST:event_resultTableMousePressed

    private void resultTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseReleased
      if(evt.isPopupTrigger()){
           row = resultTable.rowAtPoint(evt.getPoint());
              
                if (row > -1)
                {
                      
                      Object objeto = tableModel.getValueAt(row, 0);

                     String ja = objeto.toString();
                     codigo=Integer.parseInt(ja);

                }   
          menu.show(resultTable, evt.getX(), evt.getY());
      }
      else{
          if(borrar == true && entro == true){
                  try {
                sonido = null;
                sonido = AudioSystem.getClip();
                sonido.open(AudioSystem.getAudioInputStream(new File(System.getProperty("user.dir") + "\\src\\SonidosPractica\\basura.wav")));
                sonido.start();




            } catch (Exception e) {
                System.out.println("" + e);
            } // fin

               
                int messageType = JOptionPane.QUESTION_MESSAGE;
                String[] options = {"Continuar", "Cancelar"};
                int code = JOptionPane.showInternalOptionDialog(this.getContentPane(),
                        "¿Desea realmente borrar a "+nombres+" "+apellidos+"?", 
                         "Confirmacion", 1, messageType, 
                         null, options, "Cancelar");
               
                    
               
               
               if(code==0){
                    Error.Mysql("Delete from piloto where idpiloto = "+codigo);
               // reconfiguro todo 
               consulta = "SELECT idpiloto,nombre, apellido, licencia, edad, sueldo, bono, descuento, tipopiloto FROM piloto";
                      try{

                tableModel = new ResultSetTableModel( consulta );
                }
                catch ( Exception e) {
                 JOptionPane.showMessageDialog( null,
                 e );}
                      resultTable.setModel(tableModel);
                      // sonido 
                      
        
                          }
               else
                   if(code == 1){
                       
                   }
               borrar = false;
               entro=false;
               }
               
     trash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/empty.png")));         
     borrar = false;
      }
      
    }//GEN-LAST:event_resultTableMouseReleased

    private void jMenuItem1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem1MouseClicked
      
        
       
        
    }//GEN-LAST:event_jMenuItem1MouseClicked

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        try {
            Connection conexion;
            

                    // coneccion a la base de datos
            MysqlDataSource datasource= new MysqlDataSource();
            datasource.setUser("root");
            datasource.setPassword("");
            datasource.setDatabaseName("practicasp8");
            datasource.setServerName("localhost");

            conexion = (Connection) datasource.getConnection();
                        
          
                        Map beans = new HashMap();
                        ReportManager rm = new ReportManagerImpl( conexion, beans );
                        beans.put("rm", rm);
                        XLSTransformer transformer = new XLSTransformer();
                        transformer.transformXLS(System.getProperty("user.dir")+"\\src\\Plantillas\\PlantillaPlanilla.xls", beans, System.getProperty("user.dir")+"\\src\\planillaPilotos.xls");
                            
                  
                   
                    
                    
                    String file = new String(System.getProperty("user.dir")+"\\src\\PlanillaPilotos.xls");
                        
                        
            try
            {
               Process p = Runtime.getRuntime().exec ("rundll32 SHELL32.DLL,ShellExec_RunDLL "+file);
            }
            catch (Exception e)
            {
               System.out.println("Error al abrir el archivo " + file + "\n" + e.getMessage());
               }
               } catch (ParsePropertyException ex) {
            Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton6ActionPerformed

        

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
     
        d = new Descuentos();
        Descuentos.cnom.setText(""+nombre);
        Descuentos.ccod.setText(""+codigo);
        d.setVisible(true);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
   
         b = new Bono();
        Bono.cnom.setText(""+nombre);
        Bono.ccod.setText(""+codigo);
        b.setVisible(true);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
                    
    file=Archivo.TipoA("ListadoPiloto",nombre,apellido);     
    Archivo.Abrir(file);
   
    }//GEN-LAST:event_jButton7ActionPerformed

    private void cbusMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbusMouseClicked
cbus.setText("");        // TODO add your handling code here:
    }//GEN-LAST:event_cbusMouseClicked

    private void cbusKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cbusKeyReleased
  
    
   
      nombre = cbus.getText();
    
       
      consulta = "SELECT idpiloto,nombre, apellido, licencia, edad, sueldo, bono, descuento, tipopiloto FROM piloto where nombre like '"+nombre+"%' AND apellido like '"+apellido+"%'";
      try{

tableModel = new ResultSetTableModel( consulta );
}
catch ( Exception e) {
 JOptionPane.showMessageDialog( null,
 e );}
      resultTable.setModel(tableModel);
    }//GEN-LAST:event_cbusKeyReleased

    private void cbus1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbus1MouseClicked
         cbus1.setText("");
    }//GEN-LAST:event_cbus1MouseClicked

    private void cbus1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cbus1KeyReleased
        
   
      apellido = cbus1.getText();
    
       
      consulta = "SELECT idpiloto,nombre, apellido, licencia, edad, sueldo, bono, descuento tipopiloto FROM piloto where nombre like '"+nombre+"%' AND apellido like '"+apellido+"%'";
      try{

tableModel = new ResultSetTableModel( consulta );
}
catch ( Exception e) {
 JOptionPane.showMessageDialog( null,
 e );}
      resultTable.setModel(tableModel);
    }//GEN-LAST:event_cbus1KeyReleased

    private void trashMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_trashMouseMoved

  
    }//GEN-LAST:event_trashMouseMoved

    private void trashMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_trashMouseEntered
if(borrar == true){
      entro = true;
      trash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/full.png")));
}
    }//GEN-LAST:event_trashMouseEntered

    private void trashMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_trashMouseExited
entro= false;   
borrar = false;
        trash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/empty.png")));
    }//GEN-LAST:event_trashMouseExited

    private void trashMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_trashMouseReleased

    }//GEN-LAST:event_trashMouseReleased

    private void resultTableMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseMoved
    
        
    }//GEN-LAST:event_resultTableMouseMoved

    private void resultTableMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseDragged
  if(borrar == true && entro == false){
          Toolkit tk = Toolkit.getDefaultToolkit();
                Image imagen = tk.getImage(System.getProperty ("user.dir")+"\\src\\Imagenes\\basura.png");     
                Point hotSpot = new Point(0,0);  
                Cursor cursor = tk.createCustomCursor(imagen, hotSpot, "basura");
                this.setCursor(cursor);
      }        // TODO add your handling code here:
    }//GEN-LAST:event_resultTableMouseDragged

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        file=Archivo.TipoA("ListadoPiloto",nombre,apellido);      
        Correo.EnviarArchivo(Inicio.usuario,file);
    }//GEN-LAST:event_jButton8ActionPerformed


    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Piloto().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cbus;
    private javax.swing.JTextField cbus1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lnum2;
    private javax.swing.JPopupMenu menu;
    public final javax.swing.JTable resultTable = new javax.swing.JTable(tableModel);
    private javax.swing.JLabel trash;
    // End of variables declaration//GEN-END:variables

}
